#!C:\perl\bin\perl

use strict;

use IO::Socket::INET;

my @checks = (
	      {
		  "name" => "Tatooine",
		  "url" => "minaramses.homelinux.org",
		  "ports" => {
			      "Apache" => 80,
			      "FTP" => 21,
		#	      "SSH" => 22,
		#	      "POP3S" => 995,
		#	      "Bittorrent" => 6969,
			      "CVS" => 2401
			  }
		  },
	#      {
	#	  "name" => "Naboo",
	#	  "url" => "minaramses.homelinux.org",
	#	  "ports" => {
	#		      "Apache" => 80,
	#		      "FTP" => 21,
	#		      "SSH" => 22,
	#		      "POP3" => 110,
	#		      "SMTP" => 25,
	#		      "MySQL" => 3306
	#		      }
	#	  }
	      );

print "<div class=\"item-list\">";
my $hash;
for $hash (@checks)
{
    print $_;
#    my %hash = $checks[$_];
#    print $hash->{"name"};
    print "<a href=\"http://$hash->{\"url\"}\">$hash->{\"name\"}</a><br />\n";
    my ($key, $value);
    print "<ul>\n";
    while(($key, $value) = each %{$hash->{"ports"}})
    {
	print "<li>$key: ";
	my $x = check_sock($hash->{"url"}, $value);
	if ($x == 1)
	{
	    print "Down<li />\n";
	}
	else {
	    print "Up<li />\n";
	}
    }
    print "</ul>\n";
}
print "</div>";

sub check_sock()
{
    my $host = shift;
    my $port = shift;
    my $sock = IO::Socket::INET->new(PeerAddr => "$host:$port");
    if ($sock)
    {
	return 0;
    }
    else {
	return 1;
    }
}

# while (($key, $value) = each (%checks))
# {
#     %server = $value;
# #    print $key, "\n";
# }
